package com.py.androidUtils.UI;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

import com.py.androidUtils.UI.adapter.ReportAdapter;
import com.py.androidUtils.UI.model.ReportView;
import com.py.androidUtils.base.BaseActivity;
import com.py.androidUtils.utils.ListViewUtils;
import com.py.androidUtils.utils.ToastUtil;
import com.readyidu.app.R;

public class ReportActivity extends BaseActivity {
	private ListView listview;
	private TextView instructions;
	private String str = "";
	private ReportAdapter reportAdapter;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.activity_report);
		getTitleActionBar().setTitleBar("举报");
		getTitleActionBar().setImgLeft(R.drawable.icon_back, new OnClickListener() {
			@Override
			public void onClick(View v) {
				finishactivity(ReportActivity.this);
			}
		});
		getTitleActionBar().setTvRight1("提交", new OnClickListener() {
			@Override
			public void onClick(View v) {
				ToastUtil.showToast(getApplicationContext(), str);
				finishactivity(ReportActivity.this);
			}
		});
		instructions = (TextView) this.findViewById(R.id.instructions);
		listview = (ListView) this.findViewById(R.id.listview);
		reportAdapter = new ReportAdapter(ReportActivity.this);

		ReportView reportView = new ReportView();
		reportView.setId(1);
		reportView.setName("色情低俗");
		reportView.setSelect(true);
		reportAdapter.addObject(reportView);

		ReportView reportView1 = new ReportView();
		reportView1.setId(2);
		reportView1.setName("广告骚扰");
		reportView1.setSelect(false);
		reportAdapter.addObject(reportView1);

		ReportView reportView2 = new ReportView();
		reportView2.setId(3);
		reportView2.setName("政治敏感");
		reportView2.setSelect(false);
		reportAdapter.addObject(reportView2);

		ReportView reportView3 = new ReportView();
		reportView3.setId(4);
		reportView3.setName("欺诈骗钱");
		reportView3.setSelect(false);
		reportAdapter.addObject(reportView3);

		ReportView reportView4 = new ReportView();
		reportView4.setId(5);
		reportView4.setName("违法（暴力恐怖、违禁品等）");
		reportView4.setSelect(false);
		reportAdapter.addObject(reportView4);

		listview.setAdapter(reportAdapter);
		ListViewUtils.setListViewHeightBasedOnChildren(listview);
		listview.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				for (int i = 0; i < reportAdapter.getCount(); i++) {
					((ReportView) reportAdapter.getListData().get(i)).setSelect(false);
				}
				((ReportView) reportAdapter.getListData().get(position)).setSelect(true);
				reportAdapter.notifyDataSetChanged();
				ToastUtil.showToast(getApplicationContext(), ((ReportView) reportAdapter.getListData().get(position)).getName());
			}
		});

		instructions.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				launcherActivityForResult(ReportActivity.this, InstructionsActivity.class, null, 1);
			}
		});
	}

	@Override
	protected void onActivityResult(int arg0, int arg1, Intent arg2) {
		super.onActivityResult(arg0, arg1, arg2);
		if (arg1 == RESULT_OK) {
			switch (arg0) {
			case 1:
				instructions.setText(arg2.getStringExtra("instructions"));
				break;
			}
		}
	}
}
